package bramar.all;



import java.sql.Connection;
import java.sql.DriverManager;

 
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

 
public class OracleToAccessdata {

   public OracleToAccessdata(String s1) throws ClassNotFoundException, SQLException
   {
Class.forName("oracle.jdbc.driver.OracleDriver");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection ocon=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","scott","tiger");
Connection acon=DriverManager.getConnection("jdbc:odbc:accdsn");
Statement st=ocon.createStatement();
StringBuffer qry=new StringBuffer();
ResultSet rs=st.executeQuery("select * from "+s1);
qry.append("insert into ");
qry.append(s1);
qry.append(" values(");
int no=0;
ResultSetMetaData rsmd=rs.getMetaData();
	for(int i=1;i<=rsmd.getColumnCount();++i)
			{
			if(i!=1)
                            qry.append(',');
                        qry.append('?');
				 
                        } 
qry.append(")");
PreparedStatement ps=acon.prepareStatement(qry.toString());

while(rs.next())
{
     for(int i=1;i<=rsmd.getColumnCount();++i)
    {
 
     ps.setString(i,rs.getString(i));
 
    } 
         ps.executeUpdate();
}     
 rs.close();
 st.close();
 ps.close();
 acon.close();
 ocon.close();
 
    }

}
